home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / crack_4.1-tar / Scripts / RCrack < prev    next >
Encoding:
Text File  |  1992-06-25  |  3.3 KB  |  176 lines

  1. #!/bin/sh
  2.  
  3. ###
  4. # This program is copyright Alec Muffett 1991, and is provided as part of
  5. # the Crack v4.0 Password Cracking package.  The author disclaims all
  6. # responsibility or liability with respect to it's usage or its effect
  7. # upon hardware or computer systems, and maintains copyright as set out in
  8. # the "LICENCE" document which accompanies distributions of Crack v4.0 and
  9. # upwards. So there...
  10. ###
  11.  
  12. ###
  13. # For those ignorant of 'rsh', what I am trying to build is a line of
  14. # the form
  15. #          rsh hostname [-n] [-l remoteuser] command [args ...]
  16. #
  17. ###
  18.  
  19. machine=`(uname) 2>&1`            # What architecture are we on ?
  20.  
  21. ###
  22. # Map architecture to rsh-equivalent...
  23. ###
  24.  
  25. case $machine in
  26.     "HP*UX")            # Hewlett Packard boxen
  27.         remote_shell="remsh"
  28.         ;;
  29. #     "XENIX"|"Xenix")        # Just a suggestion...
  30. #        remote_shell="rcmd"
  31. #        ;;
  32.     *)                # default
  33.         remote_shell="rsh"
  34.         ;;
  35. esac
  36.  
  37. ###
  38. # Are we going to kick rsh into the background, or are we going to
  39. # background the thing on the remote end ?
  40. ###
  41.  
  42. asynch_mode=""
  43.  
  44. if [ "x$1" = "x-asynch" ]
  45. then
  46.     echo "(asynchronous $remote_shell mode)"
  47.     asynch_mode="$1"
  48.     shift
  49. else
  50.     echo "(remotely backgrounded mode)"
  51. fi
  52.  
  53. ###
  54. # Segments of input data to read.
  55. ###
  56.  
  57. startline=$1
  58. shift
  59. stopline=$1
  60. shift
  61.  
  62. datafile=/tmp/rcrk.$$        # temporary data file
  63.  
  64. ###
  65. # Awk reads from stdin... Create an input file for rsh...
  66. ###
  67.  
  68. awk -F: '
  69. BEGIN {
  70.     usercount = 0;
  71.     saltcount = 0;
  72.     startsalt = '"$startline"';
  73.     stopsalt = '"$stopline"';
  74. }
  75.  
  76. {
  77.     if (substr($3, 1, 2) != last)
  78.     {
  79.         saltcount++;
  80.         last = substr($3, 1, 2);
  81.     }
  82.  
  83.     if (saltcount >= startsalt && saltcount <= stopsalt)
  84.     {
  85.         usercount++;
  86.         print $0;
  87.     }
  88. }' > $datafile
  89.  
  90. ###
  91. # Test that we should actually bother to do anything.
  92. ###
  93.  
  94. numlines=`wc -l < $datafile`
  95.  
  96. ###
  97. # Must not quote $numlines here for comparison to work
  98. ###
  99.  
  100. if [ $numlines = 0 ]
  101. then
  102.     echo "RCrack: Nothing left to dispatch to remote host."
  103.     rm -f $datafile
  104.     exit 0
  105. else
  106.     echo Salted Segment comprises $numlines users    # Don't quote this...
  107. fi
  108.  
  109. ###
  110. # Now for the important bits. Create a diefile pointing to a remote diefile
  111. # (It's easier to get Crack.network to wire $remotediefile into arglist)
  112. ###
  113.  
  114. remhost=$1                # Name of remote host ($2 == Crack path)
  115. remotediefile=$3            # Name of remote diefile
  116. localdiefile=Runtime/DR$remhost$$    # Local pointer to above
  117.  
  118. awk -F: '
  119. BEGIN {
  120.     rshell = "'"$remote_shell"'";
  121.     rhost = "'"$remhost"'";
  122.     rdie = "'"$remotediefile"'";
  123.     rdie = substr(rdie,3,length(rdie) - 2);
  124. }
  125.  
  126. $1 == rhost {
  127.     if ($4 != "")
  128.     {
  129.         rshf = "-l " $4 " -n";
  130.     } else
  131.     {
  132.         rshf = "-n";
  133.     }
  134.     if ($5 != "")
  135.     {
  136.         nf = split($5, path, "/");
  137.         ch = path[1];
  138.         for (i = 2; i < nf; i++)
  139.         {
  140.             ch = ch "/" path[i];
  141.         }
  142.     } else
  143.     {
  144.         ch = "'"$CRACK_HOME_UNRES"'";
  145.     }
  146. }
  147.  
  148. END {
  149.     print "#!/bin/sh";
  150.     print "rm $0 && " rshell, rhost, rshf, "\"cd " ch ";" rdie "\"";
  151. }' < Scripts/network.conf > $localdiefile
  152.  
  153. chmod 700 $localdiefile
  154.  
  155. if [ "x$asynch_mode" = "x-asynch" ]
  156. then
  157.     if [ "x$CRACK_OUT" != "x" ]
  158.     then
  159.         outfile=$CRACK_OUT/out.r$$
  160.     else
  161.         outfile=./out.r$$
  162.     fi
  163.  
  164.     # 'rsh' traps SIGHUP and survives OK
  165.  
  166.     echo "Invoking: $remote_shell $@ <$datafile >$outfile 2>&1 && rm -f $datafile $localdiefile &"
  167.     $remote_shell "$@" <$datafile >$outfile 2>&1 && rm -f $datafile $localdiefile &
  168. else
  169.     # Perfectly ordinary network crack.
  170.     echo "Invoking: $remote_shell $@ < $datafile"
  171.     $remote_shell "$@" < $datafile
  172.     rm -f $datafile
  173. fi
  174.  
  175. exit 0
  176.